<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

    <!--
      Notice the use of %PUBLIC_URL% in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>AMIS Editor</title>
    <style>
      html,body{
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow:hidden;
      }
    </style>  
  </head>
  <body>
      <iframe src="index.html" id="editorIFrame" style="width:100%;height:100%;border:none"></iframe>

      <script>
        var frame = document.getElementById('editorIFrame');
        var inited = false;
        window.addEventListener("message",event=>{
          if(event.data == 'amis-editor-inited'){
            if(inited)
              return
            inited = true;
            var msg = {
              type:'setSchema',
              data: {
                type: 'page',
                title: 'Test Page',
                body: 'Demo Page'
              }
            }
            frame.contentWindow.postMessage(JSON.stringify(msg),"*")
          }else if(event.data == 'amis-editor-exit'){
            alert('exit')
          }else if(event.ata == 'amis-editor-reload'){
            var msg = {
              type:'setSchema',
              data: {
                type: 'page',
                title: 'Test Page',
                body: 'Reload Demo Page'
              }
            }
            frame.contentWindow.postMessage(JSON.stringify(msg),"*")
          }else{
            var data = JSON.parse(event.data)
            if(data.type == 'save'){
              alert('save:' + JSON.stringify(data.data))
            }
          }
        })
      </script>
  </body>
</html>
